//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "MaxCopula.h"
using namespace Cephei::QL::Math::Copulas;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Math::Copulas::CMaxCopula::CMaxCopula (boost::shared_ptr<QuantLib::MaxCopula>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMaxCopula = NULL;
#endif
	_ppMaxCopula = &childNative;
    
}
Cephei::QL::Math::Copulas::CMaxCopula::CMaxCopula (QuantLib::MaxCopula& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phMaxCopula = NULL;
#endif
	_ppMaxCopula = new boost::shared_ptr<QuantLib::MaxCopula> (&childNative);
    
    _MaxCopulaOwner = owner;
    
}

Cephei::QL::Math::Copulas::CMaxCopula::CMaxCopula (CMaxCopula^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMaxCopula = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppMaxCopula = new boost::shared_ptr<QuantLib::MaxCopula> (copy->GetShared());
        
    }
}
Cephei::QL::Math::Copulas::CMaxCopula::CMaxCopula (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMaxCopula = NULL;
#endif
	if (!t->IsSubclassOf(CMaxCopula::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Math::Copulas::CMaxCopula::CMaxCopula (QuantLib::Handle<QuantLib::MaxCopula>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMaxCopula = &childNative;
	_ppMaxCopula = &static_cast<boost::shared_ptr<QuantLib::MaxCopula>>(childNative.currentLink());
    
    _MaxCopulaOwner = owner;
}
Cephei::QL::Math::Copulas::CMaxCopula::CMaxCopula (QuantLib::Handle<QuantLib::MaxCopula> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMaxCopula = &childNative;
	_ppMaxCopula = &static_cast<boost::shared_ptr<QuantLib::MaxCopula>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Math::Copulas::CMaxCopula::CMaxCopula (QuantLib::MaxCopula childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMaxCopula = NULL;
#endif
	_ppMaxCopula = new boost::shared_ptr<QuantLib::MaxCopula> (new QuantLib::MaxCopula (childNative));
    
}
#endif

Cephei::QL::Math::Copulas::CMaxCopula::~CMaxCopula ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppMaxCopula != NULL)
    {
	    delete _ppMaxCopula;
        _ppMaxCopula = NULL;
    }
}
Cephei::QL::Math::Copulas::CMaxCopula::!CMaxCopula ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppMaxCopula != NULL)
    {
	    delete _ppMaxCopula;
    }
}
QuantLib::MaxCopula& Cephei::QL::Math::Copulas::CMaxCopula::GetReference ()
{
    if (_ppMaxCopula == NULL) throw gcnew NativeNullException ();
	return **_ppMaxCopula;
}
boost::shared_ptr<QuantLib::MaxCopula>& Cephei::QL::Math::Copulas::CMaxCopula::GetShared ()
{
    if (_ppMaxCopula == NULL) throw gcnew NativeNullException ();
	return *_ppMaxCopula;
}
QuantLib::MaxCopula* Cephei::QL::Math::Copulas::CMaxCopula::GetPointer ()
{
    if (_ppMaxCopula == NULL) throw gcnew NativeNullException ();
	return &**_ppMaxCopula;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::MaxCopula>& Cephei::QL::Math::Copulas::CMaxCopula::GetHandle ()
{
	if (_phMaxCopula == NULL)
	{
		_phMaxCopula = new Handle<QuantLib::MaxCopula> (*_ppMaxCopula);
	}
	return *_phMaxCopula;
}
#endif
bool Cephei::QL::Math::Copulas::CMaxCopula::HasNative () 
{
	return (_ppMaxCopula != NULL);
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

